import request from '@/utils/request'

// 获取文章列表
export function getArticleList() {
  return request({
    url: '/api/plants/list',
    method: 'get'
  })
}

// 获取用户发布的文章列表
export function getUserArticleList() {
  return request({
    url: '/api/plants/user/list',
    method: 'get'
  })
}

// 管理员获取所有文章列表（包括草稿）
export function getAllArticleList() {
  return request({
    url: '/api/plants/admin/list',
    method: 'get'
  })
}

// 管理员更新文章状态
export function updateArticleStatus(articleId, status) {
  return request({
    url: `/api/plants/admin/status/${articleId}`,
    method: 'put',
    params: { status }
  })
}

// 发布文章
export function createArticle(data) {
  return request({
    url: '/api/plants',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取文章详情
export function getArticleDetail(articleId) {
  return request({
    url: `/api/plants/${articleId}`,
    method: 'get'
  })
}

// 获取文章评论列表
export function getArticleComments(articleId) {
  return request({
    url: `/api/plants/${articleId}/comments`,
    method: 'get'
  })
}

// 添加文章评论
export function addArticleComment(articleId, comment) {
  return request({
    url: `/api/plants/${articleId}/comments`,
    method: 'post',
    data: comment
  })
}

// 获取评论回复列表
export function getCommentReplies(commentId) {
  return request({
    url: `/api/plants/comments/${commentId}/replies`,
    method: 'get'
  })
}

// 添加评论回复
export function addCommentReply(commentId, reply) {
  return request({
    url: `/api/plants/comments/${commentId}/replies`,
    method: 'post',
    data: reply
  })
}

// 删除评论
export function deleteComment(commentId) {
  return request({
    url: `/api/plants/comments/${commentId}`,
    method: 'delete'
  })
}

// 删除回复
export function deleteReply(replyId) {
  return request({
    url: `/api/plants/comments/replies/${replyId}`,
    method: 'delete'
  })
} 